
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/amazeui.min.css">
    <link rel="stylesheet" href="/css/amazeui.cropper.css">
    <link rel="stylesheet" href="/css/custom_up_img.css">


    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/commone.css">
    <link rel="stylesheet" media="screen and (min-width:481px)" href="/css/usercenter.css">
    <link rel="stylesheet" media="screen and (max-width:480px)" href="/css/usercenter(1).css">

    <script src="/js/hm.js"></script>
    <script type="text/javascript">
        var basePath = "/";
    </script>
    <script src="/js/common.js"></script>
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="/js/footfixed.js"></script>

    <script src="http://www.hasbei.com/static/layer/layer.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://www.hasbei.com/static/layer/theme/default/layer.css?v=3.1.1" id="layuicss-layer">
    <title>个人中心</title>


    <script src="/js/amazeui.min.js"></script>
    <script src="/js/cropper.min.js"></script>
    <script src="/js/custom_up_img.js"></script>

</head>
<body th:fragment="user_right">
    <div th:replace="common/hasbei_top_user"></div>
    <div class="content-main">
        <div class="main-info">
            <div th:replace="user/user_left"></div>
            <div class="main-user-right">

                <input type="hidden" id="no" th:value="${user.uid}">
                <div class="user-right-top">
                    <ul>
                        <li class="select-active" id="dy">
                            <a href="javascript:;">动态</a>
                        </li>
                        <li id="q" class=""><a href="javascript:;">提问&nbsp;<span th:text="${count.questioncount}" id="myUserTw">1</span></a></li>
                        <li id="an" class=""><a href="javascript:;">回答&nbsp;<span th:text="${count.ansercount}" id="myUserHd">1</span></a></li>
                        <li id="art" class=""><a href="javascript:;">文章&nbsp;<span th:text="${count.articlecount}" id="myUserWz">1</span></a></li>
                        <li id="col" class=""><a href="javascript:;">收藏&nbsp;<span th:text="${count.collectioncount}" id="myUserSc">1</span></a></li>
                    
                    </ul>
                </div>

                <div class="user-right-action">
                    <div id="myContent">

                    </div>
                    <div class="more-content">
                        <div class="load-more" style="display: none;">
                            <img src="/img/load-more.gif">
                            <span>加载中</span>
                        </div>
                        <div class="load-more-two load-more-fade" style="" onclick="moreList()">点击加载更多</div>
                        <div class="no-data" style="display: none;">┭┮﹏┭┮,没有数据啦</div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div th:replace="common/hasbei_text"></div>

</body>
<script>
   function editQaReply(obj){
       console.log(obj)
       $("#form-title").val(obj.qtitle);
       $('#form-title').attr('readonly','readonly');

       if(obj.aaContent){
           $("#textlength").text(obj.aaContent.length);
           editor.txt.html(obj.aaContent);
       }else{
           $("#textlength").text(obj.answerComment.length);
           editor.txt.html(obj.answerComment);
       }



       layer.open({
           title: "修改回答"
           , content: $('#mytext')
           , type: 1
           , area: ["auto", "auto"]
           , anim: 5
           , btn: ['yes', 'no']
           ,yes: function(index, layero){

               var content=editor.txt.text();
               var answer_id=obj.answerId;
               var aaid=obj.aidNo;

               if(content.length<=10){
                   layer.msg("回答内容不能低于10");
                   return false;
               }
               var data={};
               data['answer_id']=answer_id;
               data['aaid']=aaid;
               data['qid']=obj.qid;
               data['answer_comment']=content;
               $.ajax({
                   type: "PUT",
                   url: basePath + "answers/update",
                   data: data,
                   success: function (data) {
                       console.log(data)
                        if(data.code=='200'){
                            layer.msg("修改成功")
                            setTimeout(function(){
                                layer.closeAll(); //疯狂模式，关闭所有层
                            },1500)
                            $("#myContent").html('');
                            qaReplyList();
                        }
                   }
               });




           }
           ,btn2: function(index, layero){

           }
       });
   }
   function editArt(obj,type){
        console.log(obj)
        $("#textlength").text(obj.acontent.length)
        $("#form-title").val(obj.atitle);
        $("#form-title").removeAttr('readonly')
        editor.txt.html(obj.acontent);

        layer.open({
            title: "修改文章"
            , content: $('#mytext')
            , type: 1
            , area: ["auto", "auto"]
            , anim: 5
            , btn: ['yes', 'no']
            ,yes: function(index, layero){
                var data={};
                data['a_content']=editor.txt.text();
                data['a_title']= $("#form-title").val();
                data['uid']=obj.uid;
                data['aid']=obj.aid;
                data['type']=type;

                $.ajax({
                    type: "PUT",
                    url: basePath + "consult/update",
                    data: data,
                    success: function (data) {
                        console.log(data)
                        if(data=='ok'){
                            layer.msg("修改成功，待审核")
                            setTimeout(function(){
                                layer.closeAll(); //疯狂模式，关闭所有层
                            },1500)
                            $("#myContent").html('');
                            articleList();
                        }else{

                        }
                    }
                });

            }
            ,btn2: function(index, layero){

            }
        });
   }

   function delQa(obj) {
       var data={};
       data['qid']=obj;
       $.ajax({
           type: "POST",
           url: basePath + "qa/del",
           data: data,
           success: function (data) {
               console.log(data);
               layer.msg("删除成功！")
               $("#item"+obj).remove();
           }
       });
   }//删除提问未审核
   function delQaReply(obj,type) {

       var data={};
       if(type=='no'){
           data['aaid']=obj;
       }else{
           data['answer_id']=obj;
       }


       console.log(data)
       $.ajax({
           type: "POST",
           url: basePath + "answers/delete",
           data: data,
           success: function (data) {
               console.log(data)
               if(type=='no'){
                   $("#itemno"+obj).remove();
               }else{
                   $("#itemyes"+obj).remove();
               }

           }
       });
   }//删除回答
   function delCollect(cid) {

       var data={};
       data['cid']=cid;

       $.ajax({
           type: "POST",
           url: basePath + "sc/del",
           data: data,
           success: function (data) {
                if(data.code=='200'){
                    $('#item'+cid).remove();
                    var sum=$("#myUserSc").text();

                    $('#myUserSc').text( parseInt(sum)-1)
                    layer.msg("取消收藏成功")
                }else{
                   layer.msg("取消收藏异常，请稍后重试")
               }

           }
       });
   }//删除收藏
   function delArt(aid,type) {

       var data={};
       data['aid']=aid;
       data['type']=type;
       $.ajax({
           type: "POST",
           url: basePath + "consult/del",
           data: data,
           success: function (data) {
               if(data=='ss'){
                   $("#item"+aid).remove();
                   layer.msg('删除成功！')
               }

           }
       });
   }//删除文章
function delDy(did) {
        var data={};
        data['did']=did;
        $.ajax({
            type: "POST",
            url: basePath + "user/delDy",
            data: data,
            success: function (data) {
                console.log(data)
                if(data.code=='200'){
                    $("#item"+did).remove();
                    layer.msg('删除成功！')
                }else{
                    layer.msg('删除失败！请稍后重试')
                }



            }
        });
    }
</script>
<script>

    var current=1;
    var tabId="";
    var no=""//用户编号
    //动态数据
    function dyList(){
        $(".load-more").show();
        $(".load-more-two").hide();
        $.post(basePath+"user/index?startIndex="+current+"&uid="+no,function(data){
            $(".load-more").hide();
            //如果没有数据了就隐藏
            if(data.length==0){
                $(".load-more-two").hide();
                if(current==1){
                    $(".no-data").show();
                }
            }else{
                $(".load-more-two").show();
                $("#myContent").append(data);
            }
        });
    }
    //提问数据
    function qaList(){
        $(".load-more").show();
        $(".load-more-two").hide();
        $.post(basePath+"user/qalist?startIndex="+current+"&uid="+no,function(data){
            $(".load-more").hide();
            //如果没有数据了就隐藏
            if(data.length==0){
                $(".load-more-two").hide();
                if(current==1){
                    $(".no-data").show();
                }
            }else{
                $(".load-more-two").show();
                $("#myContent").append(data);
            }
        });
    }
    //回答数据列表
    function qaReplyList(){
        $(".load-more").show();
        $(".load-more-two").hide();
        $.post(basePath+"user/qaReplylist?startIndex="+current+"&uid="+no,function(data){
            $(".load-more").hide();
            //如果没有数据了就隐藏
            if(data.length==0){
                $(".load-more-two").hide();
                if(current==1){
                    $(".no-data").show();
                }
            }else{
                $(".load-more-two").show();
                $("#myContent").append(data);
            }
        });
    }
    //文章数据列表
    function articleList(){
        $(".load-more").show();
        $(".load-more-two").hide();
        $.post(basePath+"user/articlelist?startIndex="+current+"&uid="+no,function(data){
            $(".load-more").hide();
            //如果没有数据了就隐藏
            if(data.length==0){
                $(".load-more-two").hide();
                if(current==1){
                    $(".no-data").show();
                }
            }else{
                $(".load-more-two").show();
                $("#myContent").append(data);
            }
        });
    }
    function collectList(){//收藏
        $(".load-more").show();
        $(".load-more-two").hide();
        $.post(basePath+"user/collectList?startIndex="+current+"&uid="+no,function(data){
            $(".load-more").hide();
            //如果没有数据了就隐藏
            if(data.length==0){
                $(".load-more-two").hide();
                if(current==1){
                    $(".no-data").show();
                }
            }else{
                $(".load-more-two").show();
                $("#myContent").append(data);
            }
        });
    }
    function loadTabList(){
        if(tabId=='dy'){//动态
            dyList();
        }else if(tabId=='an'){// 回答
            qaReplyList();
        }else if(tabId=='q'){// 提问
            qaList();
        }else if(tabId=='art'){// 文章
            articleList();
        }else if(tabId=="col"){//收藏
            collectList();
        }
    }





    //加载更多
    function moreList(){
        current++;
        loadTabList();
    }
    function initList(){
        no=$("#no").val();
        tabId='dy';//动态
        dyList();
    }
    initList();//初始化
    // 点击tab标签
    $(".user-right-top li").click(function(){
        var id=$(this).attr("id");
        if(id==tabId){
            return ;
        }
        tabId=id;
        current=1;
        $("#myContent").html("");
        $(".load-more-two").hide();
        $(".no-data").hide();
        loadTabList();
        $("li").removeClass("select-active");
        $(this).addClass("select-active");
    })



    $(".change-info-show").hide();
    $(".change-info-btn").click(function(){
        $(".change-info-top").hide();
        $(".change-info-show").show();
    })
    $(".write-box-input").change(function(){
        var inputle = $(this).val().length;
        $(".write-box-span i").text(inputle);
    })
    $(".write-box-textarea").change(function(){
        var textareale = $(this).val().length;
        $(".write-box-right i").text(textareale);
    })
    $(".write-box-input").focus(function(){
        $(this).parent().css("border-color","rgba(41,167,230,1)");
    })
    $(".write-box-input").blur(function(){
        $(this).parent().css("border-color","#ddd");
    })
    $(".write-box-textarea").focus(function(){
        $(this).parent().css("border-color","rgba(41,167,230,1)");
    })
    $(".write-box-textarea").blur(function(){
        $(this).parent().css("border-color","#ddd");
    })
    $(".sure-btn").click(function(){
        var inputval = $(".write-box-input").val();
        var textareaval =$(".write-box-textarea").val();
        if(inputval == "" || textareaval == ""){
            alert("请输入信息");
            return false;
        }
        $(".h3-name").text(inputval);
        $(".p-style").text(textareaval);

        $(".change-info-show").hide();
        $(".change-info-top").show();
    })
    $(".close-btn").click(function(){
        $(".change-info-show").hide();
        $(".change-info-top").show();
    })




</script>
</html>